﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace MetaSharp.Transformation.Tests.Patterns
{
	public class ParseTests
	{
        [Fact]
		public async Task ParsesSinglePatternSuccessfully()
		{
			var result = await Pattern.Match(Pattern.Value('a'), "a");
			Assert.Equal('a', result.Value);
		}

        [Fact]
		public async Task ParsesTwoPatternSuccessfully()
		{
			var result = await Pattern.Match(
                Pattern.Transform(
                    Pattern.Value('a'), 
                    Pattern.Value('a')), 
                "a");
			Assert.Equal('a', result.Value);
		}

        [Fact]
		public async Task FirstPatternProducesArraySecondPatternParsesSuccessfully()
		{
            var p = Pattern.Transform(
                Pattern.Production(Pattern.Value('a'), () => new[] { 1, 2, 3 }),
                Pattern.ExactQuantity(Pattern.Range(1, 3), 3));
            var m = await Pattern.Match(p, "a");

            Assert.True(m.Matched);
		}

        [Fact]
		public async Task ParsesMultipleTiersOfStrings()
		{
			var letters = Pattern.ExactQuantity(Pattern.Range('a', 'z'), 3);
		    var p = Pattern.Transform(
                letters,
                letters);
            var m = await Pattern.Match(p, "abc");

			Assert.Equal(new object[] { 'a', 'b', 'c' }, m.Value);
		}

        [Fact]
        public async Task MatchingSucceedsEvenIfNotAtEndOfStream()
        {
            var m = await Pattern.Match(Pattern.Any(), "ab");
            Assert.True(m.Matched);
        }
    }
}
